# -*- coding: utf-8 -*-
# Created by zhangyanqi on 2018/4/15

"""
给定一个整数数组和一个目标值，找出数组中和为目标值的两个数。

你可以假设每个输入只对应一种答案，且同样的元素不能被重复利用。

示例:

给定 nums = [2, 7, 11, 15], target = 9

因为 nums[0] + nums[1] = 2 + 7 = 9
所以返回 [0, 1]
"""


class Solution:
    def twoSum(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: List[int]
        """
        # for i in range(0, len(nums)):
        #     for j in range(i + 1, len(nums)):
        #         if i+1 >= len(nums):
        #             break
        #         if nums[i] + nums[j] == target:
        #             return [i, j]
        # return [0, 0]
        print(len(nums))
        mydict = {}
        for i in range(0, len(nums)):
            mydict[str(nums[i])] = i

        for i in range(0, len(nums)):
            t = target - nums[i]
            get = mydict.get(str(t))
            if get is not None and get != i:
                return [i, get]


if __name__ == "__main__":
    s = Solution()
    two_sum = s.twoSum([3, 2, 4], 6)
    # print(two_sum)
